/* 
 * @Title        (����):GetDate.java  
 * @Description  (���):
 * @author       (����):�̴��
 * @data         (ʱ��):2018��8��16�� ����9:28:29 
 * @version:  V1.0 
 */

package com.spc.util;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.Date;

public class GetDate {

	public static Long getNetworkDate() {
        try {
            URL url = new URL("http://www.ntsc.ac.cn");
            URLConnection conn = url.openConnection();
            conn.connect();
            long dateL = conn.getDate();
//            Date date = new Date(dateL);
//            SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
//            return dateFormat.format(date);
            return dateL;
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return (long) 0;
    }
	
	public static Date getNetworkTime() {
        try {
            URL url = new URL("http://www.ntsc.ac.cn");
            URLConnection conn = url.openConnection();
            conn.connect();
            long dateL = conn.getDate();
            Date date = new Date(dateL);
            return date;
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
	
	
}
